import json

import requests
from requests import request

import api
from tools.getloger import GetLogger

logger = GetLogger().get_logger()


class ApiMp:
    # application = 'app'
    # application_client_type = 'weixin'
    login = ''

    def __init__(self):
        # path = '&application={}&application_client_type={}'.format(self.application, self.application_client_type)
        # 登录URL  http://shop-xo.hctestedu.com?s=api/user/login&application=app&application_client_type=weixin

        self.url_login = (str)(api.host + "?s=api/user/login" + api.path)
        self.url_get_order_Information = (str)(api.host + "?s=api/order/index" + api.path)

    def api_mp_login(self, accounts, pwd, type):
        """
        :param accounts: 用户名
        :param pwd: 密码
        :param type: 登录类型
        :return:
        """

        data = {
            "accounts": accounts,
            "pwd": pwd,
            "type": type
        }

        logger.info("正在调用登陆接口登录的账户:{}，密码:{},登录类型{}".format(accounts, pwd, type))
        return requests.post(url=self.url_login, json=data)

    def api_mp_article(self, token):
        """
        :param token:
        :return:
        """
        new_url=self.url_get_order_Information+"&token="+token
        logger.info("正在调用自媒体发布文章接口，请求url{},数据:{}".format(new_url,token))
        return requests.post(url=new_url)


if __name__ == '__main__':
    data = {
        "accounts": "hami",
        "pwd": "123456",
        "type": "username"
    }
    login = ApiMp().api_mp_login("hami", "123456", "username")
    print(login.json().get('data').get('token'))
